package com.topway.dsmflex.dao;

import java.sql.Connection;

import java.text.SimpleDateFormat;

import org.apache.log4j.Logger;

import com.topway.dsmflex.model.synchro.DataSourceBean;
import com.topway.dsmflex.util.JdbcHelp;




/**
 * 
 * @author liusy 2013-05-2
 *
 */
public abstract class BaseDao {
	
	protected SimpleDateFormat formatDate = new SimpleDateFormat(JdbcHelp.TIMESTAMP_FORMAT);
	protected SimpleDateFormat formatTime = new SimpleDateFormat(JdbcHelp.TIMESTAMP_FORMAT);
	protected SimpleDateFormat formatStamp = new SimpleDateFormat(JdbcHelp.TIMESTAMP);

	
	private static Logger log = Logger.getLogger(BaseDao.class);
	
	protected DataSourceBean ds = null; 
	protected Connection conn = null;
	
	
	protected Connection getConnection(DataSourceBean  _dsSource)
	{
		if(null!=_dsSource)
		{
			if(null==ds || !ds.getDataSourceName().equals(_dsSource.getDataSourceName()))
			{
		
				try {
					ds = _dsSource;
					conn = JdbcHelp.getConnection(ds);
				} catch (Exception e) {
					log.error(e.getMessage());
					e.printStackTrace();
				}
			}
		}
		return conn;
	}

}
